package com.team.engine.permission.action;

import javax.annotation.Resource;

import com.team.engine.common.exception.FailedServiceException;
import com.team.engine.common.exception.NullServiceException;
import com.team.engine.common.exception.TypeServiceException;
import com.team.engine.common.view.BaseActionAbs;
import com.team.engine.permission.service.PermissionServiceImpl;

public class PermissionAction extends BaseActionAbs {

	private static final long serialVersionUID = -5724631907246320245L;
	
	@Resource
	private PermissionServiceImpl permissionServiceImpl;
	
	public void setPermissionServiceImpl(PermissionServiceImpl permissionServiceImpl) {
		this.permissionServiceImpl = permissionServiceImpl;
	}

	public String addModule() throws RuntimeException {
		String tokenSession = (String) session.get("token");
		if(tokenSession != null && tokenSession.equals(this.token)){
			this.request.setAttribute("error", "请不要重复提交");
			return ERROR;
		}
		
		try {
			this.permissionServiceImpl.addModule(this.request.getParameterMap());
			
		} catch (FailedServiceException e) {
			this.request.setAttribute("error", e.getMessage());
			return ERROR;
		} catch (NullServiceException e) {
			this.request.setAttribute("error", e.getMessage());
			return ERROR;
		} catch (TypeServiceException e) {
			this.request.setAttribute("error", e.getMessage());
			return ERROR;
		}
		
		this.session.put("token", this.token);
		return SUCCESS;
	}
	
}
